package com.elinkway.infinitemovies.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.elinkway.infinitemovies.bean.ChannelDetail;
import com.elinkway.infinitemovies.bean.ChannelDetailList;
import com.le123.ysdq.R;
import com.nostra13.universalimageloader.core.ImageLoader;

public class ChannelDetailGridAdapter extends MyBaseAdapter {

	private ChannelDetailList item_data;
	
	
	private class GridItemHolder {
		ImageView poster;
		TextView title;
		TextView intro;
	}

	public ChannelDetailGridAdapter(Context context, ChannelDetailList data) {
		super(context);
		this.item_data = data;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ChannelDetail detail = item_data.getChannelDetails().get(position);
		GridItemHolder holder;
		if (convertView == null) {
			convertView = inflater.inflate(R.layout.grid_item_poster_small,
					parent,false);
			holder = new GridItemHolder();
			holder.poster = (ImageView) convertView
					.findViewById(R.id.grid_item_poster);
			holder.title = (TextView) convertView
					.findViewById(R.id.grid_item_title);
			holder.intro = (TextView) convertView
					.findViewById(R.id.grid_item_intro);
			convertView.setTag(holder);
		} else {
			holder = (GridItemHolder) convertView.getTag();
		}
		ImageLoader.getInstance().displayImage(detail.getPoster(),
				holder.poster);
		// item.poster.setImageResource((Integer) map.get("poster"));
		holder.title.setText(detail.getName());
		String episodeInfo = detail.getEpisodeInfoInString();
		holder.intro.setVisibility(View.GONE);
		if(!TextUtils.isEmpty(episodeInfo)){
			holder.intro.setText(episodeInfo);
			holder.intro.setVisibility(View.VISIBLE);
		}
//		holder.desc.setText(detail.get);
		return convertView;
	}

	@Override
	public int getCount() {
		return item_data.getChannelDetails().size();
	}

	public void addItem_data(ChannelDetailList result) {
		item_data.addChannelDetails(result.getChannelDetails());
		notifyDataSetChanged();
	}

	public void setItem_data(ChannelDetailList result) {
		item_data = result;
		notifyDataSetChanged();
	}

}
